<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link type="text/css" rel="stylesheet" href="/css/css_all.css" />
    <script src="https://code.jquery.com/jquery-1.11.0.js"></script>
    <script type="text/javascript">
        /*
         * 上传文件
         */
        function upload(){
            var formData = new FormData($( "#uploadfiles" )[0]);
           //  var formData = new FormData();
           //  formData.append("file", $( "#uploadfiles" )[0][0]);
           //  formData.append("name", $( "#uploadfiles" )[0][1]);
            $.ajax({
                type: "post",
                encType: 'multipart/form-data',
                url: "/ExcelToDb/sendData",
                dataType: "json",
                data: formData,
                /**
                 *必须false才会自动加上正确的Content-Type
                 */
                contentType : false,
                /**
                 * 必须false才会避开jQuery对 formdata 的默认处理
                 * XMLHttpRequest会对 formdata 进行正确的处理
                 */
                processData : false,
                traditional: true,

                success: function(data){//从后端返回数据进行处理
                    if(data){
                        alert("上传成功！");
                    }else{
                        alert("上传失败！");
                    }
                },
                error: function(err) {//提交出错
                    $("#msg").html(JSON.stringify(err));//打出响应信息
                    alert("服务器无响应");
                }
            });
        }
    </script>
</head>
<body>
<div class="screen_center">
<script>
    alert("第一行将作为数据库的字段名！！！")
</script>
    <form id="uploadfiles">

        Address: <input name="address" value="192.168.1.173"> <br />
        Port: <input name="port" value="27017"> <br />
        DbName: <input name="dbName" value="Db-Excel-Transform-Test"> <br />
        Collection: <input name="collection" value="Test"> <br />
        选择文件：<input type="file" name="multipartFile "><br>
<!--        文件名称：<input type="text" name="name"><br>-->
        <input type="button" value="上传" onclick="upload()" />
    </form>
</div>
</body>
</html>